
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections;
using System.Xml;
using Swaf.BizObj;

	
namespace Swaf.BizObj.xml
{
	/// <summary> Maintains its own XML <c>org.dom4j.Element</c> for the data store of its
	/// properties.
	/// *
	/// </summary>
	/// <author>  mdenman
	/// 
	/// </author>
	[Serializable]
	public class XmlBusinessObject:XmlBaseBusinessObject, IXmlNodeParent
	{
		/// <summary>Creates a new instance of XmlBusinessObject 
		/// </summary>
		public XmlBusinessObject(IBizObjDefinition type, XmlElement baseEl)
			:base(type)
		{
			m_base = baseEl;
		}
		
		protected internal override XmlElement xmlElement
		{get{
			return m_base;
		}}
		
		protected internal void setElement(XmlElement el)
		{
			m_base = el;
		}

		public XmlElement getChildElement(string name, bool createIfNeeded)
		{
			XmlElement el = null;
			IBizObjField field = (IBizObjField)type.Fields[name];
			if(field != null)
			{
				if(field.BizType == BizFieldType.NetClass)
					return m_base;
				else
				{
					el = Cmn.findChildWithName(m_base, name);
					if(el == null && createIfNeeded)
					{
						el = (XmlElement)m_base.AppendChild(m_base.OwnerDocument.CreateElement(name));
					}
				}
			}
			return el;
		}

		public override IEnumerator GetEnumerator() { return null; }
		private XmlElement m_base;
	}
}